package com.qishon.pc.domain.service;

import com.qishon.pc.domain.util.GirardEnum;
import com.qishon.pc.domain.util.JointUtil;
import com.qishon.pc.domain.util.SplitUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * Created by yongwei.chen on 2017/1/3.
 */
@Component
@Slf4j
@RabbitListener(queues = "jointReceiver")
public class JointReceiverService {
    @Value("${run.path}")
    private String runPath;

    @Value("${image.TypeNum}")
    private String imageTypeNum;

    @Value("${image.Types}")
    private  String imageTypes;

    @Value("${image.Types.heights}")
    private  String imageTypesheights;

    @RabbitHandler
    public void process(String msg){
        log.info("jointReceiver:" + msg);
        String[] strArr = msg.split(",");
        int girardId = Integer.parseInt(strArr[0]);
        String taskName = strArr[2];
        String getPath = GirardEnum.findByKey(girardId-1).getFilePtah();
        String path= runPath + "\\" + getPath+"\\"+taskName;
        String savePath=GirardEnum.findByKey(girardId).getFilePtah();
        boolean isX=true;
        try {
            JointUtil.SplitJoint(path,isX,savePath/*,taskName*/);
            SplitUtil a=new SplitUtil();
            a.SplitTools(runPath,imageTypeNum,imageTypes,imageTypesheights,taskName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
